package kr.co.insoft.core.service.configration.sev.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import kr.co.insoft.core.model.configration.sev.SevMappingEntityModel;

import org.springframework.util.StringUtils;

public class SevMappingCompute {

	final String orchid;
	final String variables;

	public SevMappingCompute(String orchid, String variables) {
		this.orchid = orchid;
		this.variables = variables;
	}

	public boolean isExist() {
		return StringUtils.hasLength(variables);
	}

	public List<SevMappingEntityModel> getMappings() throws Exception {
		List<SevMappingEntityModel> mappings = null;
		if (isExist()) {
			Set<String> duplicate = new HashSet<String>();
			for (String variableid : variables.split(",")) {
				duplicate.add(variableid);
			}
			
			mappings = new ArrayList<SevMappingEntityModel>();
			for (String variableid : duplicate) {
				mappings.add(new SevMappingEntityModel(orchid, variableid));
			}
		}
		return mappings;
	}
}
